package com.jacklin.serializer;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.util.Date;

/**
 * Date类型转换为Long类型，继承JsonSerializer<Date>抽象类，并重写serializer方法
 *
 * @Author:JackLin
 * @Create 2019/4/1 0:11
 */
public class Date2LongSerializer extends JsonSerializer<Date> {
    @Override
    public void serialize(Date date, JsonGenerator jsonGenerator, SerializerProvider serializers) throws IOException, JsonProcessingException{
        jsonGenerator.writeNumber(date.getTime()/1000);
    }
}
